﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DataControl;
using System.Data;
using System.Text;

namespace ATW.MT.BUS
{
    public class bus_C_SealLevel
    {
        DataAccess da = null;
        public bus_C_SealLevel()
        {
            da = new DataAccess();
        }
        #region 方法
        /// <summary>
        /// 密封等级
        /// </summary>
        /// <param name="name"></param>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public DataTable SealPagerQuery(string name, int page, int pagesize)
        {
            string sql = "select top 100 percent * from C_SealLevel where rowstatus<>'2'";
            if (!String.IsNullOrEmpty(name))
            {
                sql += " and LevelType='" + name + "'";
            }
            sql += " order by LevelType desc";
            return da.PageSize(sql, page, pagesize, "SealLevelID","create_time desc");
        }
        public DataTable SealQuery(string pid)
        {
            StringBuilder sql=new StringBuilder();
            sql.AppendFormat(@"select S.* from T_Production_Seal PS left join C_SealLevel S on PS.SealLevelID=S.SealLevelID 
                where PS.ProductionID='{0}' order by LevelType desc,Level asc", pid);
            return da.ExecuteDataTable(sql.ToString());
        }
        /// <summary>
        /// 新增密封等级
        /// </summary>
        /// <param name="type"></param>
        /// <param name="level"></param>
        /// <returns></returns>
        public int SealAdd(string type, string level)
        {
            string sql = "insert into [C_SealLevel] ([LevelType],[Level]) values('" + type + "','" + level + "')";
            return da.ExcuteNoQuery(sql);
        }
        /// <summary>
        /// 修改密封等级
        /// </summary>
        /// <param name="type"></param>
        /// <param name="level"></param>
        /// <param name="slid"></param>
        /// <returns></returns>
        public int SealEdit(string type, string level, string slid)
        {
            string sql = "update C_SealLevel set [LevelType] ='" + type + "',[Level]='" + level + "' where [SealLevelID]='" + slid + "'";
            return da.ExcuteNoQuery(sql);
        }
        /// <summary>
        /// 密封等级是否存在
        /// </summary>
        /// <param name="type"></param>
        /// <param name="level"></param>
        /// <returns></returns>
        public bool isSealExist(string type, string level)
        {
            string sql = "select * from [C_SealLevel] where [LevelType]='" + type + "' and [SealLevelID]='" + level + "'";
            DataTable dt = da.ExecuteDataTable(sql);
            if (dt != null && dt.Rows.Count > 0)
            {
                return true;
            }
            return false;
        }
        #endregion
    }
}